<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>必要性与工作原理 | Awesome-笔记</title>
    <meta name="generator" content="VuePress 1.9.10">
    <link rel="icon" href="icons/favicon.ico">
    <meta name="description" content="">
    <meta name="author" content="热爱生活，喜欢睡觉">
    <meta name="about" content="这是一个专门用于记录笔记的静态资源网站">
    
    <link rel="preload" href="/awesome-notebook/assets/css/0.styles.ad5756f5.css" as="style"><link rel="preload" href="/awesome-notebook/assets/js/app.5520c9b0.js" as="script"><link rel="preload" href="/awesome-notebook/assets/js/2.778bb4ad.js" as="script"><link rel="preload" href="/awesome-notebook/assets/js/1.50b457b8.js" as="script"><link rel="preload" href="/awesome-notebook/assets/js/34.4ce6ff0d.js" as="script"><link rel="prefetch" href="/awesome-notebook/assets/js/10.325b9f09.js"><link rel="prefetch" href="/awesome-notebook/assets/js/11.c62b6b34.js"><link rel="prefetch" href="/awesome-notebook/assets/js/12.ecdb524b.js"><link rel="prefetch" href="/awesome-notebook/assets/js/13.3f3f6a36.js"><link rel="prefetch" href="/awesome-notebook/assets/js/14.eb7a3d07.js"><link rel="prefetch" href="/awesome-notebook/assets/js/15.114dfd5c.js"><link rel="prefetch" href="/awesome-notebook/assets/js/16.85253907.js"><link rel="prefetch" href="/awesome-notebook/assets/js/17.c2838453.js"><link rel="prefetch" href="/awesome-notebook/assets/js/18.3256f17f.js"><link rel="prefetch" href="/awesome-notebook/assets/js/19.d8afd0ae.js"><link rel="prefetch" href="/awesome-notebook/assets/js/20.10e47ab9.js"><link rel="prefetch" href="/awesome-notebook/assets/js/21.33b300c9.js"><link rel="prefetch" href="/awesome-notebook/assets/js/22.b7c97fbe.js"><link rel="prefetch" href="/awesome-notebook/assets/js/23.e9994ecc.js"><link rel="prefetch" href="/awesome-notebook/assets/js/24.8cc3e1e8.js"><link rel="prefetch" href="/awesome-notebook/assets/js/25.dedb1585.js"><link rel="prefetch" href="/awesome-notebook/assets/js/26.9422829f.js"><link rel="prefetch" href="/awesome-notebook/assets/js/27.9802cd87.js"><link rel="prefetch" href="/awesome-notebook/assets/js/28.d9f287bc.js"><link rel="prefetch" href="/awesome-notebook/assets/js/29.dc9b14bd.js"><link rel="prefetch" href="/awesome-notebook/assets/js/3.af33e5d6.js"><link rel="prefetch" href="/awesome-notebook/assets/js/30.645d0efa.js"><link rel="prefetch" href="/awesome-notebook/assets/js/31.164808cf.js"><link rel="prefetch" href="/awesome-notebook/assets/js/32.59287e4c.js"><link rel="prefetch" href="/awesome-notebook/assets/js/33.3031be3e.js"><link rel="prefetch" href="/awesome-notebook/assets/js/35.d58eebcc.js"><link rel="prefetch" href="/awesome-notebook/assets/js/4.45665f8a.js"><link rel="prefetch" href="/awesome-notebook/assets/js/5.7098d77a.js"><link rel="prefetch" href="/awesome-notebook/assets/js/6.0c0a0f39.js"><link rel="prefetch" href="/awesome-notebook/assets/js/7.6a854e57.js"><link rel="prefetch" href="/awesome-notebook/assets/js/vendors~docsearch.5e19b665.js">
    <link rel="stylesheet" href="/awesome-notebook/assets/css/0.styles.ad5756f5.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/awesome-notebook/" class="home-link router-link-active"><img src="/awesome-notebook/imgs/hero.png" alt="Awesome-笔记" class="logo"> <span class="site-name can-hide">Awesome-笔记</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/awesome-notebook/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="三件套" class="dropdown-title"><span class="title">三件套</span> <span class="arrow down"></span></button> <button type="button" aria-label="三件套" class="mobile-dropdown-title"><span class="title">三件套</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          css
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/css/css学习.html" class="nav-link">
  css笔记
</a></li><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/css/css面试题.html" class="nav-link">
  css面试题
</a></li></ul></li><li class="dropdown-item"><h4>
          js
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/js/es6语法学习.html" class="nav-link">
  es6语法学习
</a></li><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/js/js常用操作.html" class="nav-link">
  js常用操作
</a></li><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/js/js面试题.html" class="nav-link">
  js面试题
</a></li><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/js/js数据对象及API.html" class="nav-link">
  js常用API
</a></li><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/js/js_knowledge_1.html" class="nav-link">
  其他js知识
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="服务端" class="dropdown-title"><span class="title">服务端</span> <span class="arrow down"></span></button> <button type="button" aria-label="服务端" class="mobile-dropdown-title"><span class="title">服务端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/awesome-notebook/服务端/express框架.html" class="nav-link">
  express框架
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="工程化" class="dropdown-title"><span class="title">工程化</span> <span class="arrow down"></span></button> <button type="button" aria-label="工程化" class="mobile-dropdown-title"><span class="title">工程化</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          vue相关
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/awesome-notebook/工程化/vue/vue2笔记.html" class="nav-link">
  vue2笔记
</a></li></ul></li><li class="dropdown-item"><h4>
          webpack相关
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/awesome-notebook/工程化/webpack相关/webpack使用.html" class="nav-link">
  wepack笔记
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发工具" class="dropdown-title"><span class="title">开发工具</span> <span class="arrow down"></span></button> <button type="button" aria-label="开发工具" class="mobile-dropdown-title"><span class="title">开发工具</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/awesome-notebook/开发工具/git笔记.html" class="nav-link">
  git笔记
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="小程序" class="dropdown-title"><span class="title">小程序</span> <span class="arrow down"></span></button> <button type="button" aria-label="小程序" class="mobile-dropdown-title"><span class="title">小程序</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/awesome-notebook/小程序相关/微信小程序笔记.html" class="nav-link">
  微信小程序原生
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/awesome-notebook/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="三件套" class="dropdown-title"><span class="title">三件套</span> <span class="arrow down"></span></button> <button type="button" aria-label="三件套" class="mobile-dropdown-title"><span class="title">三件套</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          css
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/css/css学习.html" class="nav-link">
  css笔记
</a></li><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/css/css面试题.html" class="nav-link">
  css面试题
</a></li></ul></li><li class="dropdown-item"><h4>
          js
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/js/es6语法学习.html" class="nav-link">
  es6语法学习
</a></li><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/js/js常用操作.html" class="nav-link">
  js常用操作
</a></li><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/js/js面试题.html" class="nav-link">
  js面试题
</a></li><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/js/js数据对象及API.html" class="nav-link">
  js常用API
</a></li><li class="dropdown-subitem"><a href="/awesome-notebook/三件套/js/js_knowledge_1.html" class="nav-link">
  其他js知识
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="服务端" class="dropdown-title"><span class="title">服务端</span> <span class="arrow down"></span></button> <button type="button" aria-label="服务端" class="mobile-dropdown-title"><span class="title">服务端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/awesome-notebook/服务端/express框架.html" class="nav-link">
  express框架
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="工程化" class="dropdown-title"><span class="title">工程化</span> <span class="arrow down"></span></button> <button type="button" aria-label="工程化" class="mobile-dropdown-title"><span class="title">工程化</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          vue相关
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/awesome-notebook/工程化/vue/vue2笔记.html" class="nav-link">
  vue2笔记
</a></li></ul></li><li class="dropdown-item"><h4>
          webpack相关
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/awesome-notebook/工程化/webpack相关/webpack使用.html" class="nav-link">
  wepack笔记
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发工具" class="dropdown-title"><span class="title">开发工具</span> <span class="arrow down"></span></button> <button type="button" aria-label="开发工具" class="mobile-dropdown-title"><span class="title">开发工具</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/awesome-notebook/开发工具/git笔记.html" class="nav-link">
  git笔记
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="小程序" class="dropdown-title"><span class="title">小程序</span> <span class="arrow down"></span></button> <button type="button" aria-label="小程序" class="mobile-dropdown-title"><span class="title">小程序</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/awesome-notebook/小程序相关/微信小程序笔记.html" class="nav-link">
  微信小程序原生
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>必要性与工作原理</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/awesome-notebook/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/git%E7%AC%94%E8%AE%B0.html#git-缺点" class="sidebar-link">git 缺点：</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/awesome-notebook/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/git%E7%AC%94%E8%AE%B0.html#创建-git-仓库" class="sidebar-link">创建 git 仓库</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/awesome-notebook/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/git%E7%AC%94%E8%AE%B0.html#git-版本追溯" class="sidebar-link">git 版本追溯</a></li><li class="sidebar-sub-header"><a href="/awesome-notebook/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/git%E7%AC%94%E8%AE%B0.html#git-推送三部曲" class="sidebar-link">git 推送三部曲</a></li><li class="sidebar-sub-header"><a href="/awesome-notebook/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/git%E7%AC%94%E8%AE%B0.html#git-拉取" class="sidebar-link">git 拉取</a></li></ul></li><li><a href="/awesome-notebook/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/git%E7%AC%94%E8%AE%B0.html#git-分支管理" class="sidebar-link">git 分支管理</a><ul class="sidebar-sub-headers"></ul></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="必要性与工作原理"><a href="#必要性与工作原理" class="header-anchor">#</a> 必要性与工作原理</h1> <p>软件开发过程，通过文件备份方式管理代码版本，十分不便，使用版本控制工具进行管理</p> <h1 id="版本控制工具-git-与-svn"><a href="#版本控制工具-git-与-svn" class="header-anchor">#</a> 版本控制工具 git 与 svn</h1> <ul><li>git：分布式版本控制工具。备份、记录、回滚、共享、团协</li> <li>svn：集中式版本控制工具,所有版本所有项目放在一个服务器中</li> <li>gitee、github：基于 git，分布式版本控制+集中式管理版本项目的仓库，不仅可以分布式互相共享版本，分支合并检验</li></ul> <h2 id="git-缺点"><a href="#git-缺点" class="header-anchor">#</a> git 缺点：</h2> <ul><li><p>git 使用分布式模型，意味着没有一个中央处理器来保存权威数据，每一个开发人员都拥有代码和所有历史记录的完整副本，当项目较大时，会导致存储库越来越大</p></li> <li><p>git 操作本地库时执行非常快，但使用远程库时，其限制就明显：存储库的更改基于的版本需要完全一致，才能允许提交，每次提交之前必须从远程仓库获取到所有的更新。其他版本管理工具只需要更新当前修改的文件而不需要全部更新</p></li> <li><p>没有一次只更新一个文件或几个文件的能力</p></li> <li><p>git 默认针对于本地存储库进行工作，无法及时知道远程仓库已经被做了哪些修改，git 只能对文本文件进行合并，二进制文件无法合并只能替换，无法及时了解远程仓库状态，只有将本地仓库和远程仓库合并时才能发现冲突</p></li> <li><p>访问控制，对于每一个用户其某个目录某个文件的访问权限</p></li> <li><p>git 作为一个命令行工具，对初学者和非程序人员不友好</p></li></ul> <h1 id="git-使用"><a href="#git-使用" class="header-anchor">#</a> git 使用</h1> <div class="language-shell extra-class"><pre class="language-shell"><code><span class="token comment">#初始化</span>
<span class="token function">git</span> init
<span class="token comment"># 克隆远程仓库</span>
<span class="token function">git</span> clone url
</code></pre></div><h2 id="创建-git-仓库"><a href="#创建-git-仓库" class="header-anchor">#</a> 创建 git 仓库</h2> <ul><li><code>git init</code>命令使用一个已经存在的目录作为 git 仓库，在一个指定目录执行该命令后就生成了一个新的 git 仓库，然后就可以使用其他 git 命令来管理跟踪代码变更并与远程仓库交互</li></ul> <h3 id="git-版本追溯"><a href="#git-版本追溯" class="header-anchor">#</a> git 版本追溯</h3> <p>在 github 或 gitee 上查看历次提交的记录及对应的版本号，而本地则可以使用如下命令进行版本回溯</p> <div class="language-shell extra-class"><pre class="language-shell"><code><span class="token function">git</span> reset <span class="token parameter variable">--hard</span> 版本号
</code></pre></div><h3 id="git-推送三部曲"><a href="#git-推送三部曲" class="header-anchor">#</a> git 推送三部曲</h3> <div class="language-shell extra-class"><pre class="language-shell"><code><span class="token function">git</span> <span class="token function">add</span> <span class="token builtin class-name">.</span>       <span class="token comment">#将工作区代码都上传到暂存区</span>
<span class="token function">git</span> commit <span class="token parameter variable">-m</span> <span class="token string">'一些描述性内容'</span>          <span class="token comment"># 讲暂存区内容提交到分支</span>
<span class="token function">git</span> push origin 分支名      //提交到远程仓库
</code></pre></div><h3 id="git-拉取"><a href="#git-拉取" class="header-anchor">#</a> git 拉取</h3> <div class="language-shell extra-class"><pre class="language-shell"><code><span class="token function">git</span> pull origin 分支名
</code></pre></div><h2 id="git-分支管理"><a href="#git-分支管理" class="header-anchor">#</a> git 分支管理</h2> <div class="language-shell extra-class"><pre class="language-shell"><code><span class="token function">git</span> branch      <span class="token comment">#查看分支</span>
<span class="token function">git</span> branch 分支名称         <span class="token comment"># 创建分支</span>
<span class="token function">git</span> checkout 分支名称       <span class="token comment">#切换分支</span>
<span class="token function">git</span> push origin 分支名称:分支名称        <span class="token comment">#本地分支同步到远程分支</span>
<span class="token function">git</span> merge 分支名称          <span class="token comment">#将分支合并到master</span>
</code></pre></div><ul><li>执行 git init 时，会默认创建一个 master 分支</li></ul> <div class="language-shell extra-class"><pre class="language-shell"><code>$ <span class="token function">git</span> branch  <span class="token comment"># 列出所有分支</span>
  develop
* master    <span class="token comment"># *表示当前分支，</span>
</code></pre></div><ul><li>使用 branch 创建新分支后，本地的 git 仓库也会分为 master 和若干子分支，使用 checkout 进行分支切换，对应文件夹里的内容也会发生改变</li> <li>实际开发中经常使用至少三个分支，由于要保证 master 分支始终为稳定的版本，除了 develop 和 master 分支外，其他分支的代码要先合并到 develop 分支中，当 develop 分支中的代码没有问题后再合并到 master</li></ul> <h1 id="git-日常使用"><a href="#git-日常使用" class="header-anchor">#</a> git 日常使用</h1> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> status
<span class="token comment"># 拉取远程仓库内容以进行同步</span>
<span class="token function">git</span> pull origin master
<span class="token comment"># 上传文件</span>
<span class="token function">git</span> <span class="token function">add</span> <span class="token builtin class-name">.</span>
<span class="token function">git</span> commit <span class="token parameter variable">-m</span> <span class="token string">'本次修改的描述'</span>
<span class="token function">git</span> push origin master
</code></pre></div></div> <footer class="page-edit"><!----> <!----></footer> <!----> </main></div><div class="global-ui"></div></div>
    <script src="/awesome-notebook/assets/js/app.5520c9b0.js" defer></script><script src="/awesome-notebook/assets/js/2.778bb4ad.js" defer></script><script src="/awesome-notebook/assets/js/1.50b457b8.js" defer></script><script src="/awesome-notebook/assets/js/34.4ce6ff0d.js" defer></script>
  </body>
</html>
